home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet Info 1994 March
/
Internet Info CD-ROM (Walnut Creek) (March 1994).iso
/
networking
/
ip
/
ka9q
/
MNetsrc.hqx
/
Mac TCP_IP Source v.33
/
tcpdump.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-02-22
|
2KB
|
89 lines
#include <stdio.h>
#include "global.h"
#include "mbuf.h"
#include "netuser.h"
#include "internet.h"
#include "timer.h"
#include "tcp.h"
#include "trace.h"
#ifdef MAC
extern int tcptrcflg;
extern FILE *trcwndp;
#endif
/* TCP segment header flags */
char *tcpflags[] = {
"FIN", /* 0x01 */
"SYN", /* 0x02 */
"RST", /* 0x04 */
"PSH", /* 0x08 */
"ACK", /* 0x10 */
"URG" /* 0x20 */
};
/* Dump a TCP segment header. Assumed to be in network byte order */
void
tcp_dump(bpp,source,dest,check)
struct mbuf **bpp;
int32 source,dest; /* IP source and dest addresses */
int check; /* 0 if checksum test is to be bypassed */
{
int i;
struct tcp seg;
struct pseudo_header ph;
int16 csum;
if(bpp == NULLBUFP || *bpp == NULLBUF)
return;
/* Verify checksum */
ph.source = source;
ph.dest = dest;
ph.protocol = TCP_PTCL;
ph.length = len_mbuf(*bpp);
csum = cksum(&ph,*bpp,ph.length);
ntohtcp(&seg,bpp);
#ifdef MAC
fprintf(trcwndp,"TCP: %u->%u Seq x%lx",seg.source,seg.dest,seg.seq,seg.ack);
if(seg.flags & ACK)
fprintf(trcwndp," Ack x%lx",seg.ack);
for(i=0;i<6;i++){
if(seg.flags & 1 << i){
fprintf(trcwndp," %s",tcpflags[i]);
}
}
fprintf(trcwndp," Wnd %u",seg.wnd);
if(seg.flags & URG)
fprintf(trcwndp," UP x%x",seg.up);
/* Print options, if any */
if(seg.mss != 0)
fprintf(trcwndp," MSS %u",seg.mss);
if(check && csum != 0)
fprintf(trcwndp," CHECKSUM ERROR (%u)",i);
fprintf(trcwndp,"\n");
#else
printf("TCP: %u->%u Seq x%lx",seg.source,seg.dest,seg.seq,seg.ack);
if(seg.flags & ACK)
printf(" Ack x%lx",seg.ack);
for(i=0;i<6;i++){
if(seg.flags & 1 << i){
printf(" %s",tcpflags[i]);
}
}
printf(" Wnd %u",seg.wnd);
if(seg.flags & URG)
printf(" UP x%x",seg.up);
/* Print options, if any */
if(seg.mss != 0)
printf(" MSS %u",seg.mss);
if(check && csum != 0)
printf(" CHECKSUM ERROR (%u)",i);
printf("\n");
#endif
}